package me.pearjelly.pmc.dao.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.PreparedStatementSetter;

/**
 * @author xiaobinghan
 * 
 */
public class DocumentPreparedStatementSetter implements PreparedStatementSetter {
	private static final int MAXROWS = 2000;
	private int startIndex;
	private int limit;
	private int flag;

	public DocumentPreparedStatementSetter() {
		this.startIndex = 0;
		this.limit = MAXROWS;
		this.flag = 1;
	}

	public DocumentPreparedStatementSetter(int startIndex, int limit, int flag) {
		this.startIndex = startIndex;
		this.limit = limit;
		this.flag = flag;
	}

	@Override
	public void setValues(PreparedStatement ps) throws SQLException {
		int i = 1;
		ps.setInt(i++, this.flag);
		ps.setInt(i++, this.startIndex);
		ps.setInt(i++, this.flag);
		ps.setInt(i++, this.limit);
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public void setFlags(int flag) {
		this.flag = flag;
	}
}
